I am trying save the sessions in Set allSession , but the getOpenSessions() method creating an empty array. My code looks like -
@OnOpen
public void onOpen(Session session){
System.out.println(session.getId() + " has opened a connection");
System.out.println(" Session: "+session.getOpenSessions());
try {
session.getBasicRemote().sendText("Connection Established");
} catch (IOException ex) {
ex.printStackTrace();
}
}
So, It's giving me an result -
1 has opened a connection
Session []
Can anyone suggest what is the exact problem here?
Sorry for the delayed answer. The bug was tomcat version 8.0. Tomcat 7 is more stable. I am using this from 3,4 months but session related issue is coming. Hope this information will help you.
i got the same problem...but when i used the method in the @onMessage annotation method ..it works fine...the set is showing the elements...
this worked!
@OnMessage
public String echo(String msg) throws IOException {
Set<Session> set1 = wsSession.getOpenSessions();
System.out.println("set: "+set1);
Iterator<Session> iter = set1.iterator();
while(iter.hasNext()) {
System.out.println("entered inside while");
}
}